using System;
using System.IO;
using System.Text.RegularExpressions;

namespace SDET.Util
{
    public class egrep
    {
        public static void Main(string[] args)
        {
            string line;
            string pattern;
            Regex regex;
            TextReader __in__ = null;

            if (args.Length < 1) { return; }

            pattern = args[0];
            regex = new Regex(pattern);
           
            if (args.Length == 1)
            {
                __in__ = Console.In;
            }


            if (args.Length == 2 && System.IO.File.Exists(args[1]))
            {
                __in__ =  new System.IO.StreamReader(args[1]);

            }

            while(__in__.Peek() != -1)
            {
               line = __in__.ReadLine();
               if (regex.IsMatch(line))
               {
                   Console.WriteLine ("{0}", line);
               }
            }
            __in__.Close();
        }
    }
}